package com.tsd.jxc.goods.service.impl;

import java.util.List;
import java.util.Map;
import java.util.Date;
import javax.annotation.Resource;

import com.tsd.core.utils.HlpUtils;
import com.tsd.core.vo.PageBean;
import com.tsd.jxc.goods.service.JxcGoodsAttrGroupService;
import com.tsd.jxc.goods.entity.JxcGoodsAttrGroup;
import com.tsd.jxc.goods.entity.JxcGoodsAttrGroupExt;
import com.tsd.system.entity.SysUser;
import com.tsd.jxc.goods.dao.JxcGoodsAttrGroupMapper;
import org.springframework.stereotype.Service;
import com.tsd.service.BaseServiceImpl;

/**
 * 描述：JxcGoodsAttrGroup 服务实现层
 *
 * @author david
 * @date 2024/05/08 10:06:10
 */
@Service
public class JxcGoodsAttrGroupServiceImpl extends BaseServiceImpl implements JxcGoodsAttrGroupService {

    @Resource
    private JxcGoodsAttrGroupMapper jxcGoodsAttrGroupMapper;

    @Override
    public JxcGoodsAttrGroup getJxcGoodsAttrGroupById(Long id)throws Exception {
        return jxcGoodsAttrGroupMapper.selectByPrimaryKey(id);
    }

    @Override
    public JxcGoodsAttrGroupExt queryBySid(String sid) throws Exception {
    return jxcGoodsAttrGroupMapper.selectBySid(sid);
    }

    @Override
    public void deleteJxcGoodsAttrGroups(List<String> list, SysUser opUser)throws Exception {
        for (String sid:list){
            JxcGoodsAttrGroup old = jxcGoodsAttrGroupMapper.selectBySid(sid);
            super.checkEmpty(old,"该记录不存在");
            super.autoInjectBaseData(old,opUser,TYPE_DELETE);
            jxcGoodsAttrGroupMapper.updateByPrimaryKeySelective(old);
        }
    }

    @Override
    public void saveJxcGoodsAttrGroup(JxcGoodsAttrGroup record, SysUser opUser) throws Exception {
    	if (HlpUtils.isEmpty(record.getId())) {
            super.checkEmpty(record.getName(),"请输入名称");
            super.autoInjectBaseData(record,opUser,TYPE_CREATE);
    		jxcGoodsAttrGroupMapper.insertSelective(record);
    	} else {
            super.autoInjectBaseData(record,opUser,TYPE_UPDATE);
    		jxcGoodsAttrGroupMapper.updateByPrimaryKeySelective(record);
    	}
    }

    @Override
    public List<JxcGoodsAttrGroupExt> findJxcGoodsAttrGroups(Map<String, Object> params, PageBean page) throws Exception {
    	return jxcGoodsAttrGroupMapper.selectByPage(params, page);
    }

    @Override
    public List<JxcGoodsAttrGroupExt> findJxcGoodsAttrGroups(Map<String, Object> params) throws Exception {
        return jxcGoodsAttrGroupMapper.selectByParams(params);
    }
}
